/*
 * uc_led.c
 *
 *  Created on: Feb 7, 2013
 *      Author: George
 */
#include "common.h"

void uc_led_all_off();
void uc_led_all_on();
void uc_led_all_toggle();
void uc_led_init();
void uc_led_off(int p_led);
void uc_led_on(int p_led);
void uc_led_toggle(int p_led);


void uc_led_all_off()
{
	//Calls uc_led_off() four times to turn all LED's off.
	int i;
	for(i=1; i <= 4; i++)
		uc_led_off(i);
}

void uc_led_all_on()
{
	int i;
	for(i=1; i <= 4; i++)
		uc_led_on(i);
}

void uc_led_all_toggle()
{
	//Calls uc_led_toggle() four times to toggle all LED's.
	int i;
	for(i=1; i <= 4; i++)
		uc_led_toggle(i);
}

void uc_led_init()
{
	//Calls gpio_port_tc_init() four times to initalize the pin that each LED is connected to.
	gpio_port_tc_init();
}

void uc_led_off(int p_led)
{
	//Calls gpio_port_tc_set_pin_state() to set the state of the pin for LED p_led to turn the LED off.
	
	gpio_port_tc_set_pin_state(p_led-1, 0);
	
}

void uc_led_on(int p_led)
{
	//Calls gpio_port_tc_set_pin_state() to set the state of the pin for LED p_led to turn the LED on.
	gpio_port_tc_set_pin_state(p_led-1, 1);
}

void uc_led_toggle(int p_led)
{
	//Calls gpio_port_tc_get_pin_state() to determine if LED p_led is on or off. It it is on, turn it off or if it is off, turn it on.
	if(gpio_port_tc_get_pin_state(p_led-1) == 0)
		uc_led_on(p_led);
	else
		uc_led_off(p_led);
}
